#if UNITY_EDITOR
    using UnityEngine;
    using Sirenix.OdinInspector.Editor;
    using Sirenix.OdinInspector.Editor.Drawers;
    using Sirenix.Utilities.Editor;
    using Sirenix.Utilities;
    using UnityEditor;
using Lockstep.Game;
using Sirenix.OdinInspector;
using Lockstep.ECS.ECDefine;
using System.Linq;
using System;

// 
// In Character.cs we have a two dimention array of ItemSlots which is our inventory.
// And instead of using the the TableMatrix attribute to customize it there, we in this case 
// instead create a custom drawer that will work for all two-dimentional ItemSlot arrays,
// so we don't have to make the same CustomDrawer via the TableMatrix attribute again and again.
// 

internal sealed class WallInfoCellDrawer<TArray> : TwoDimensionalArrayDrawer<TArray, WallCellConfig>
        where TArray : System.Collections.IList
{
    WallCellConfig[] allWallCellConfig;
    WallCellConfig[] GetWallCellConfigs() {
        if (allWallCellConfig == null) {
            allWallCellConfig = AssetDatabase.FindAssets("t:WallCellConfig").Select(guid => AssetDatabase.LoadAssetAtPath<WallCellConfig>(AssetDatabase.GUIDToAssetPath(guid))).ToArray();

        }
        return allWallCellConfig;
    }
        protected override TableMatrixAttribute GetDefaultTableMatrixAttributeSettings()
    {
        return new TableMatrixAttribute()
            {
                SquareCells = true,
                HideColumnIndices = true,
                HideRowIndices = true,
                ResizableColumns = false
            };
        }

        protected override WallCellConfig DrawElement(Rect rect, WallCellConfig value)
        {
            if (value != null)
            {
                var id = DragAndDropUtilities.GetDragAndDropId(rect);
                if (value.type != SceneObjType.None && value.prefab)
                {
                    Texture pre2D = AssetPreview.GetAssetPreview(value.prefab);
                    EditorGUI.DrawPreviewTexture(rect.Padding(5).AlignCenterXY(20), pre2D);
                }
            }
            SceneObjType type = (SceneObjType)EditorGUI.EnumPopup(rect.Padding(5).AlignBottom(16), value == null ? SceneObjType.None : value.type);
            value = GetWallCellConfigs().Where(x => x.type == type).FirstOrDefault();
            return value;
        } 

        protected override void DrawPropertyLayout(GUIContent label)
        {
            base.DrawPropertyLayout(label);

            // Draws a drop-zone where we can destroy items.
            var rect = GUILayoutUtility.GetRect(0, 40).Padding(2);
            var id = DragAndDropUtilities.GetDragAndDropId(rect);
            DragAndDropUtilities.DrawDropZone(rect, null as UnityEngine.Object, null, id);
            //DragAndDropUtilities.DropZone<ItemSlot>(rect, new ItemSlot(), false, id);
        }
    }

#endif
